package com.example.zht.wechat;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ProgressBar;

public class StartActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        ImageView iv = findViewById(R.id.imageView);
        iv.setImageResource(R.drawable.icon_launch);
        // 后台处理耗时任务
        new Thread(new Runnable() {
            @Override
            public void run() {
                // 耗时任务，比如加载网络数据
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        // 跳转至 MainActivity
                        startActivity(new Intent(StartActivity.this, MainActivity.class));
                        // 结束当前的 Activity
                        StartActivity.this.finish();
                    }
                });
            }
        }).start();
        /* 定时启动主界面，通常用于广告投放
            Integer time = 2000;    //设置等待时间，单位为毫秒
            Handler handler = new Handler();
            // 当计时结束时，跳转至主界面
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    startActivity(new Intent(StartActivity.this, MainActivity.class));
                    StartActivity.this.finish();
                }
            }, time);
         */
    }
}
